package com.thirteen.app.controller;

import com.thirteen.app.dto.CreatePaperResponse.PaperCreateDto;
import com.thirteen.app.service.CollegeService;
import com.thirteen.app.service.CourseService;
import com.thirteen.app.service.PaperService;
import com.thirteen.app.service.QuestionRepositoryService;
import com.thirteen.app.utils.tools.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = {"创建考试"})
@RestController
@RequestMapping("/api/teacher/paper")
@CrossOrigin
public class CreatePaperController {

    @Resource
    QuestionRepositoryService questionRepositoryService;

    @Resource
    PaperService paperService;

    @Resource
    CollegeService collegeService;

    @Resource
    CourseService courseService;

    @ApiOperation("新建试卷获取学院")
    @GetMapping("getAcademy")
    public CommonResult queryAllCollegeAndCourse() {
        return CommonResult.success(collegeService.queryAllCollege());
    }

    @ApiOperation("新建试卷获取课程")
    @GetMapping("getCourse")
    public CommonResult queryAllCollegeAndCourse(Integer collegeId) {
        return CommonResult.success(courseService.queryAllCourseByCollegeId(collegeId));
    }

//    @ApiOperation("抽题组卷获取题库")
//    @GetMapping("getQuestionRepository")
//    public CommonResult queryQuestionRepository(String repositoryName) {
//        return CommonResult.success(questionRepositoryService.queryRepository(repositoryName));
//    }

    @ApiOperation("自组创建试卷")
    @PostMapping("customCreatePaper")
    public CommonResult customCreatePaper(@RequestBody PaperCreateDto paperCreateDto) {
        System.out.println(paperCreateDto.toString());
        if (!paperService.customCreatePaper(paperCreateDto)) {
            return CommonResult.failed();
        }
        return CommonResult.success("success");
    }

}
